﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using LightWeightORM.ORM.TableAccessor;
using SmartWarehouse.Common;
using SmartWarehouse.ORM.Entity;
using SmartWarehouse.Config;


namespace SmartWarehouse
{
    namespace BussinessLogic
    {
        namespace Basis
        {
            /// <summary>
            /// Summary description for InventoryFacade
            /// </summary>
            public class InventoryFacade
            {
                private TableAccessor<SwInventory> _inventoryAccessor;

                public TableAccessor<SwInventory> InventoryAccessor
                {
                    get { return _inventoryAccessor; }
                    set { _inventoryAccessor = value; }
                }

                public InventoryFacade()
                {
                    this.InventoryAccessor = AccessorFactory.InventoryAccessor;
                }

                public DataTable GetInventory(string productName)
                {
                    return this.InventoryAccessor.ToDataTable(new Filter(SwInventory._Product_name,productName, ComparisonOperator.Equal));
                }
                public DataTable GetInventoryByOrder(string orderType)
                {
                    DataView dvInventory = this.InventoryAccessor.ToDataTable().AsDataView();

                    if (orderType.Equals("ProductName", StringComparison.OrdinalIgnoreCase))
                    {
                        dvInventory.Sort = "Product_Name";
                    }
                    else if (orderType.Equals("Warehouse", StringComparison.OrdinalIgnoreCase))
                    { 
                        dvInventory.Sort = "Cur_Warehouse";
                    }
                    else if(orderType.Equals("Location", StringComparison.OrdinalIgnoreCase))
                    {
                        dvInventory.Sort = "Cur_Location";
                    }
                    else if(orderType.Equals("Bin", StringComparison.OrdinalIgnoreCase))
                    {
                        dvInventory.Sort = "Cur_Bin";
                    }
                    else
                    {
                        throw new ApplicationException("排序方式不存在");
                    }

                    return dvInventory.ToTable();
                }
            }
        }
    }
}
